//
//  RouteLine_ViewController.m
//  CarNetwork_logistics
//
//  Created by 高启 on 15/11/11.
//  Copyright © 2015年 turingEdu. All rights reserved.
//

#import "RouteLine_ViewController.h"
#import "MultiMpleList_ViewController.h"
@interface RouteLine_ViewController ()

@end

@implementation RouteLine_ViewController
{
    UIView   *fromAreaView;
    UIView   *toView;
    NSString *fromProviceStr;   // 出发地省名
    NSString *fromProviceCode;  // 出发地省code
    NSString *fromCityStr;
    NSString *toProviceStr;
    NSString *toCityStr;
    UIButton *from_provice_btn; // 出发地的省
    UIButton *from_city_btn;    // 出发地的市
    UIButton *from_provice_btn2;//目的地的省
    UIButton *from_city_btn2;   // 目的地的市
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navtitle.text = @"选择路线";
    [self createView];
    // Do any additional setup after loading the view.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setTabbarBadge:) name:@"selectProvinceNotification" object:nil];
}

/**
 *  选择完成省或市发送过来的通知
 *
 *  @param 传过来的省市信息
 */
-(void)setTabbarBadge:(NSNotification*)noteInfo{
    NSDictionary *userInfo = [noteInfo userInfo];
    NSString *tempTag = [userInfo objectForKey:@"tag"];
    if ([tempTag isEqualToString:@"101"]) {
        // "省"的信息
        fromProviceStr = [userInfo objectForKey:@"provienceName"];
        fromProviceCode = [userInfo objectForKey:@"provienceCode"];
        [from_provice_btn setTitle:fromProviceStr forState:UIControlStateNormal];
    } else if ([tempTag isEqualToString:@"102"]){
        // “市”的信息
        // 取出市的名字
        NSString *cityName = [userInfo objectForKey:@"cityName"];
        [from_city_btn setTitle:cityName forState:UIControlStateNormal];
    } else if ([tempTag isEqualToString:@"201"]){
        // "省"的信息
        fromProviceStr = [userInfo objectForKey:@"provienceName"];
        fromProviceCode = [userInfo objectForKey:@"provienceCode"];
        [from_provice_btn2 setTitle:fromProviceStr forState:UIControlStateNormal];
    } else if ([tempTag isEqualToString:@"202"]){
        // “市”的信息
        // 取出市的名字
        NSString *cityName = [userInfo objectForKey:@"cityName"];
        [from_city_btn2 setTitle:cityName forState:UIControlStateNormal];
    }
}
/**
 *  总的view管理方法
 */
- (void)createView
{
    [self.view setBackgroundColor:[UIColor HexStrWithColor:@"f4f5f5"]];
    [self fromStationView];
    [self toStationView];
}
/**
 *  起始地view
 */
-(void)fromStationView
{
    UIView *topNavigationTitleView = [[UIView alloc]init];
    [self.view addSubview:topNavigationTitleView];
    [topNavigationTitleView.layer setMasksToBounds:YES];
    [topNavigationTitleView.layer setBorderWidth:1.0];
    [topNavigationTitleView.layer setBorderColor:[[UIColor HexStrWithColor:@"aaaaaa"] CGColor]];
    [topNavigationTitleView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.mas_equalTo(kStateNavHeight);
         make.centerX.equalTo(self.view);
         make.width.mas_equalTo(kUIScreenWidth + 2);
         make.height.mas_equalTo(@43);
         
     }];
    
    UIImageView *fromImageView = [[UIImageView alloc]init];
    [topNavigationTitleView addSubview:fromImageView];
    [fromImageView setContentMode:UIViewContentModeScaleToFill];
    [fromImageView setImage:[UIImage imageNamed:@"qsd"]];
    [fromImageView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.centerY.equalTo(topNavigationTitleView);
         make.left.equalTo(topNavigationTitleView.mas_left).with.offset(kUIScreenWidth*0.4);
         make.height.equalTo(topNavigationTitleView.mas_height).with.multipliedBy(0.42);
         make.width.mas_equalTo(@18);
         
     }];
    
    UILabel *fromLable = [[UILabel alloc]init];
    [topNavigationTitleView addSubview:fromLable];
    [fromLable setText:@"出发地"];
    [fromLable setTextColor:[UIColor HexStrWithColor:@"000000"]];
    [fromLable setFont:[UIFont systemFontOfSize:15]];
    [fromLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(fromImageView.mas_right).with.offset(2);
         make.centerY.equalTo(topNavigationTitleView);
         make.width.mas_equalTo(@50);
         make.height.mas_equalTo(@15);
         
     }];
    
    fromAreaView = [[UIView alloc]init];
    [fromAreaView setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:fromAreaView];
    [fromAreaView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(topNavigationTitleView.mas_bottom);
         make.centerX.equalTo(self.view);
         make.size.mas_equalTo(CGSizeMake(kUIScreenWidth,kUIScreenHeight*0.15));
         
     }];
    
    // 出发“省:”字label
    UILabel *proviceNameLable = [[UILabel alloc]init];
    [fromAreaView addSubview:proviceNameLable];
    [proviceNameLable setText:@"省:"];
    [proviceNameLable setTextAlignment:NSTextAlignmentCenter];
    [proviceNameLable setTextColor:[UIColor HexStrWithColor:@"000000"]];
    [proviceNameLable setFont:[UIFont systemFontOfSize:15]];
    [proviceNameLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(fromAreaView.mas_left);
         make.top.equalTo(fromAreaView);
         make.width.equalTo(fromAreaView.mas_width).with.multipliedBy(0.15);
         make.height.equalTo(fromAreaView.mas_height).with.multipliedBy(0.45);
         
     }];
    
    // 出发“省”按钮
    from_provice_btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [fromAreaView addSubview:from_provice_btn];
    [from_provice_btn setTag:101];
    [from_provice_btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [from_provice_btn addTarget:self action:@selector(selectProvice:) forControlEvents:UIControlEventTouchUpInside];
    [from_provice_btn mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.top.equalTo(proviceNameLable);
        make.left.equalTo(proviceNameLable.mas_right);
        make.height.equalTo(proviceNameLable);
        make.right.equalTo(fromAreaView.mas_right).with.offset(-10);
        
    }];
    
    // 出发省下面的“线”
    UILabel *from_btn_bottom_Lable = [[UILabel alloc]init];
    [fromAreaView addSubview:from_btn_bottom_Lable];
    [from_btn_bottom_Lable setBackgroundColor:[UIColor HexStrWithColor:@"6e6e6e"]];
    [from_btn_bottom_Lable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(fromAreaView.mas_left).with.offset(29);
         make.top.equalTo(from_provice_btn.mas_bottom);
         make.right.equalTo(fromAreaView.mas_right).with.offset(-29);
         make.height.mas_equalTo(@1);
         
     }];
    
    // 出发“市:”字
    UILabel *cityNameLable = [[UILabel alloc]init];
    [fromAreaView addSubview:cityNameLable];
    [cityNameLable setText:@"市:"];
    [cityNameLable setTextAlignment:NSTextAlignmentCenter];
    [cityNameLable setTextColor:[UIColor HexStrWithColor:@"000000"]];
    [cityNameLable setFont:[UIFont systemFontOfSize:15]];
    [cityNameLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(fromAreaView.mas_left);
         make.top.equalTo(proviceNameLable.mas_bottom);
         make.size.equalTo(proviceNameLable);
         
     }];
    
    // 出发“市”按钮
    from_city_btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [fromAreaView addSubview:from_city_btn];
    [from_city_btn setTag:102];
    [from_city_btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [from_city_btn addTarget:self action:@selector(selectCity:) forControlEvents:UIControlEventTouchUpInside];
    [from_city_btn mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(cityNameLable);
         make.left.equalTo(cityNameLable.mas_right);
         make.size.equalTo(from_provice_btn);
         
     }];
    
    // 出发市下面的"线"
    UILabel *from_city_bottom_Lable = [[UILabel alloc]init];
    [fromAreaView addSubview:from_city_bottom_Lable];
    [from_city_bottom_Lable setBackgroundColor:[UIColor HexStrWithColor:@"6e6e6e"]];
    [from_city_bottom_Lable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(fromAreaView.mas_left).with.offset(29);
         make.top.equalTo(from_city_btn.mas_bottom);
         make.right.equalTo(fromAreaView.mas_right).with.offset(-29);
         make.height.mas_equalTo(@1);
         
     }];
}

/**
 *  目的地view
 */
-(void)toStationView
{
    UIView *topNavigationTitleView = [[UIView alloc]init];
    [self.view addSubview:topNavigationTitleView];
    [topNavigationTitleView.layer setMasksToBounds:YES];
    [topNavigationTitleView.layer setBorderWidth:1.0];
    [topNavigationTitleView.layer setBorderColor:[[UIColor HexStrWithColor:@"aaaaaa"] CGColor]];
    [topNavigationTitleView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(fromAreaView.mas_bottom);
         make.centerX.equalTo(self.view);
         make.width.mas_equalTo(kUIScreenWidth + 2);
         make.height.mas_equalTo(@43);
         
     }];
    
    UIImageView *fromImageView = [[UIImageView alloc]init];
    [topNavigationTitleView addSubview:fromImageView];
    [fromImageView setContentMode:UIViewContentModeScaleToFill];
    [fromImageView setImage:[UIImage imageNamed:@"mdd"]];
    [fromImageView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.centerY.equalTo(topNavigationTitleView);
         make.left.equalTo(topNavigationTitleView.mas_left).with.offset(kUIScreenWidth*0.4);
         make.height.equalTo(topNavigationTitleView.mas_height).with.multipliedBy(0.42);
         make.width.mas_equalTo(@18);
         
     }];
    
    UILabel *fromLable = [[UILabel alloc]init];
    [topNavigationTitleView addSubview:fromLable];
    [fromLable setText:@"目的地"];
    [fromLable setTextColor:[UIColor HexStrWithColor:@"000000"]];
    [fromLable setFont:[UIFont systemFontOfSize:15]];
    [fromLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(fromImageView.mas_right).with.offset(2);
         make.centerY.equalTo(topNavigationTitleView);
         make.width.mas_equalTo(@50);
         make.height.mas_equalTo(@15);
         
     }];
    
    toView = [[UIView alloc]init];
    [toView setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:toView];
    [toView mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(topNavigationTitleView.mas_bottom);
         make.centerX.equalTo(self.view);
         make.size.mas_equalTo(CGSizeMake(kUIScreenWidth,kUIScreenHeight*0.13));
         
     }];
    
    // 目的地“省:”字
    UILabel *proviceNameLable = [[UILabel alloc]init];
    [toView addSubview:proviceNameLable];
    [proviceNameLable setText:@"省:"];
    [proviceNameLable setTextAlignment:NSTextAlignmentCenter];
    [proviceNameLable setTextColor:[UIColor HexStrWithColor:@"000000"]];
    [proviceNameLable setFont:[UIFont systemFontOfSize:15]];
    [proviceNameLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(toView.mas_left);
         make.top.equalTo(toView);
         make.width.equalTo(toView.mas_width).with.multipliedBy(0.15);
         make.height.equalTo(toView.mas_height).with.multipliedBy(0.45);
         
     }];
    
    // 目的地“省”的按钮
    from_provice_btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [toView addSubview:from_provice_btn2];
    [from_provice_btn2 setTag:201];
    [from_provice_btn2 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [from_provice_btn2 addTarget:self action:@selector(selectProvice:) forControlEvents:UIControlEventTouchUpInside];
    [from_provice_btn2 mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(proviceNameLable);
         make.left.equalTo(proviceNameLable.mas_right);
         make.height.equalTo(proviceNameLable);
         make.right.equalTo(toView.mas_right).with.offset(-10);
         
     }];
    
    // 目的地省下面的“线”
    UILabel *from_btn_bottom_Lable = [[UILabel alloc]init];
    [toView addSubview:from_btn_bottom_Lable];
    [from_btn_bottom_Lable setBackgroundColor:[UIColor HexStrWithColor:@"6e6e6e"]];
    [from_btn_bottom_Lable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(toView.mas_left).with.offset(29);
         make.top.equalTo(from_provice_btn2.mas_bottom);
         make.right.equalTo(toView.mas_right).with.offset(-29);
         make.height.mas_equalTo(@1);
         
     }];
    
    // 目的地"市:"字
    UILabel *cityNameLable = [[UILabel alloc]init];
    [toView addSubview:cityNameLable];
    [cityNameLable setText:@"市:"];
    [cityNameLable setTextAlignment:NSTextAlignmentCenter];
    [cityNameLable setTextColor:[UIColor HexStrWithColor:@"000000"]];
    [cityNameLable setFont:[UIFont systemFontOfSize:15]];
    [cityNameLable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(toView.mas_left);
         make.top.equalTo(proviceNameLable.mas_bottom);
         make.size.equalTo(proviceNameLable);
         
     }];
    
    // 目的地“市”的按钮
    from_city_btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [toView addSubview:from_city_btn2];
    [from_city_btn2 setTag:202];
    [from_city_btn2 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [from_city_btn2 addTarget:self action:@selector(selectCity:) forControlEvents:UIControlEventTouchUpInside];
    [from_city_btn2 mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(cityNameLable);
         make.left.equalTo(cityNameLable.mas_right);
         make.size.equalTo(from_provice_btn2);
         
     }];
    
    // 目的地市下面的"线"
    UILabel *from_city_bottom_Lable = [[UILabel alloc]init];
    [toView addSubview:from_city_bottom_Lable];
    [from_city_bottom_Lable setBackgroundColor:[UIColor HexStrWithColor:@"6e6e6e"]];
    [from_city_bottom_Lable mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.left.equalTo(toView.mas_left).with.offset(29);
         make.top.equalTo(from_city_btn2.mas_bottom);
         make.right.equalTo(toView.mas_right).with.offset(-29);
         make.height.mas_equalTo(@1);
         
     }];

    
    UIButton *finishBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:finishBtn];
    [finishBtn addTarget:self action:@selector(finishedAction:) forControlEvents:UIControlEventTouchUpInside];
    [finishBtn setTitle:@"完成" forState:UIControlStateNormal];
    [finishBtn setBackgroundColor:[UIColor HexStrWithColor:@"d23700"]];
    [finishBtn.layer setMasksToBounds:YES];
    [finishBtn.layer setCornerRadius:4];
    [finishBtn mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.top.equalTo(toView.mas_bottom).with.offset(62);
        make.left.equalTo(self.view.mas_left).with.offset(20);
        make.right.equalTo(self.view.mas_right).with.offset(-20);
        make.height.mas_equalTo(@45);
        
    }];
}

/**
 *  选择省得列表的响应方法
 *
 *  @param btn
 */
- (void)selectProvice:(UIButton *)btn
{
    MultiMpleList_ViewController *ereaVC = [[MultiMpleList_ViewController alloc]init];
    ereaVC.title = @"选择路线";
    ereaVC.type = @"0";
    if (btn.tag == 101) {
        // 出发省
        ereaVC.from = @"0";
    } else if (btn.tag == 201){
        // 目的省
        ereaVC.from = @"1";
    }
    [self.navigationController pushViewController:ereaVC animated:YES];
}

/**
 *  选择市的列表响应方法
 *
 *  @param btn {
 
 */
- (void)selectCity:(UIButton *)btn
{
    MultiMpleList_ViewController *ereaVC = [[MultiMpleList_ViewController alloc]init];
    ereaVC.title = @"选择路线";
    ereaVC.provinceCode = fromProviceCode;
    ereaVC.type = @"1";
    if (btn.tag == 102) {
        // 出发市
        ereaVC.from = @"0";
    } else if (btn.tag == 202){
        // 目的市
        ereaVC.from = @"1";
    }
    [self.navigationController pushViewController:ereaVC animated:YES];
}

/**
 *  完成选择的方法
 *
 *  @param btn {
 */
- (void)finishedAction:(UIButton *)btn
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
